package com.nali.dal.statement.function;

import com.nali.dal.statement.util.number.NumberOperateUtil;


public abstract class NumberOperater<T> extends DoubleArgumentDataHandler<Number, T> {

	@Override
	protected T handle(Number arg1, Number arg2) throws FunctionException {
		int numberLevel = NumberOperateUtil.numberLevel(arg1, arg2);
		switch (numberLevel) {
		case 0:
			return handleDouble(arg1.doubleValue(), arg2.doubleValue());
		case 1:
			return handleLong(arg1.longValue(), arg2.longValue());
		case 2:
			return handleInteger(arg1.intValue(), arg2.intValue());
		default:
			throw new RuntimeException("won't happen?");
		}
	}

	protected T handleInteger(int value1, int value2) {
		return handleLong(value1, value2);
	}

	protected T handleLong(long value1, long value2) {
		return handleDouble(value1, value2);
	}

	protected abstract T handleDouble(double value1, double value2);

}
